<template>
    <div class="lesson-container" :class="{ 'is-mobile': $isMobile }">
        <div v-for="item in datas" :key="item.id" class="lesson-item">
            <div class="item-title" v-if="item.lessons && item.lessons.length">{{ item.title }}</div>

            <div class="item-infos">
                <div class="item-detail" v-for="(lesson, index) in item.lessons" :key="index" @click="handleToDetail(lesson)">
                    <div class="cover">
                        <img :src="lesson.coverImage" alt="">
                    </div>

                    <div class="title">
                        {{ lesson.title }}
                    </div>

                    <div class="desc" v-if="lesson.desc"> {{ lesson.desc }}</div>
                </div>
            </div>
        </div>

    </div>
</template>

<script>
export default {
    name: "lessonList",
    data() {
        return {
            datas: []
        }
    },
    mounted() {
        this.getData();
    },
    methods: {

        async getData() {
            const loading = this.$loading();
            const { data } = await this.$fetch.get(`/api/topic/lessonList`);
            this.datas = data;
            loading.close()
        },

        handleToDetail(item) {
            this.$router.push({
                name: "lesson-video",
                query: {
                    lessonId: item.id,
                    topicId: item.topicId,
                }
            })
        }

    }
}
</script>

<style lang="less" scoped>
.lesson-container {
    padding-left: 60px;
    width: 100%;
    box-sizing: border-box;
    height: 100%;


    .lesson-item {
        display: flex;
        flex-direction: column;
        font-size: 16px;
        margin-right: 20px;
        margin-top: 20px;
        cursor: pointer;

        .item-title {
            height: 34px;
            min-width: 166px;
            max-width: max-content;
            background: url(~@/assets/topic-title-bg.png) center center no-repeat;
            background-size: cover;
            font-family: PingFangSC, PingFang SC;
            font-weight: 600;
            font-size: 16px;
            text-indent: 14px;
            color: #FFFFFF;
            line-height: 34px;
            text-align: left;
            font-style: normal;
            cursor: default;
        }

        .item-infos {
            display: flex;
            flex-direction: row;
            flex-wrap: wrap;
            width: 100%;
            margin-top: 16px;

  

            /* 示例：轻微放大 */


            .item-detail {
                display: flex;
                flex-direction: column;
                justify-content: center;
                align-items: center;
                background: #F8F9FB;
                border-radius: 8px;
                margin-right: 20px;
                margin-bottom: 20px;
                padding-bottom: 20px;
                width: calc(33% - 20px);
                height: max-content;
                transition: all 0.3s ease;

                &:hover {
                    transform: scale(1.05);
                }

                .name {
                    margin-top: 10px;
                    font-family: PingFangSC, PingFang SC;
                    font-weight: 600;
                    font-size: 16px;
                    color: #333333;
                    line-height: 22px;
                    text-align: center;
                    font-style: normal;
                }



            }
        }
    }

    .cover {
        width: 272px;
        height: 142px;

        img {
            width: 100%;
            height: 100%;
            border-radius: 8px;
            object-fit: cover;
        }



        .lesson {
           
        }
    }

    .title {
        font-family: PingFangSC, PingFang SC;
        font-weight: 600;
        font-size: 16px;
        color: #333333;
        line-height: 22px;
        font-style: normal;
        margin-top: 14px;
        width: 100%;
        padding: 0 20px;
        text-align: center;
    }

    .desc {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 12px;
        width: 100%;
        padding: 0 20px;
        color: #484848;
        line-height: 17px;
        text-align: center;
        font-style: normal;
        margin-top: 8px;
        white-space: pre;
    }

}

.lesson-container.is-mobile {
    display: flex;
    padding-left: 10px;
    flex-direction: column;

    .lesson-item {
        margin-right: 10px;
        margin-top: 10px;
        width: 100%;
    }

    .item-infos {
        margin: 0 auto;
        margin-top: 10px;
        width: 90%;

        .item-detail {
            width: 100%;

        }
    }

    .cover {
        width: 100%;
    }
}
</style>